package com.px.system.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.px.common.utils.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.px.common.constant.Constants;
import com.px.common.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.px.system.domain.MeetingTypeDO;
import com.px.system.service.MeetingTypeService;
import com.px.common.utils.PageUtils;
import com.px.common.utils.R;

/**
 * 会议类型
 * 
 * @author 品讯科技
 * @email zly@hnpinxun.cn
 * @date 2024-08
 */
 
@Controller
@RequestMapping("/system/meetingType")
public class MeetingTypeController extends BaseController {
	@Autowired
	private MeetingTypeService meetingTypeService;
    private String prefix = "system/meetingType";
	@GetMapping()
	@RequiresPermissions("system:meetingType:meetingType")
	String MeetingType(){
	    return prefix+"/meetingType";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:meetingType:meetingType")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        startPage();
        List<MeetingTypeDO> list =  meetingTypeService.list(params);
        PageUtils dataTable = getDataTable(list);
        return dataTable;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:meetingType:add")
	String add(){
	    return prefix+"/add";
	}

	@GetMapping("/edit/{id}")
    @RequiresPermissions("system:meetingType:edit")
    String edit(@PathVariable("id") String id,Model model){
		MeetingTypeDO meetingType = meetingTypeService.get(id);
        model.addAttribute("meetingType", meetingType);
        return prefix+"/edit";
    }
    @GetMapping("/view/{id}")
    @RequiresPermissions("system:meetingType:meetingType")
    String view(@PathVariable("id") String id,Model model){
			MeetingTypeDO meetingType = meetingTypeService.get(id);
        model.addAttribute("meetingType", meetingType);
        return prefix+"/view";
    }
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:meetingType:add")
	public R save( MeetingTypeDO meetingType){
		meetingType.setId(IdUtil.getStrId());
        meetingType.setCreateTime(new Date());
        meetingType.setCreateUser(getUserId());
        meetingType.setUpdateTime(new Date());
        meetingType.setUpdateUser(getUserId());
		if(meetingTypeService.save(meetingType)){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:meetingType:edit")
	public R update( MeetingTypeDO meetingType){
        meetingType.setUpdateTime(new Date());
        meetingType.setUpdateUser(getUserId());
		meetingTypeService.updateById(meetingType);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:meetingType:remove")
	public R remove( String id,Integer status){

		MeetingTypeDO data=meetingTypeService.getById(id);
        data.setDelFlag(status);
        if(meetingTypeService.updateById(data)){
            return R.ok();
        }
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:meetingType:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
		MeetingTypeDO data=new MeetingTypeDO();
        data.setDelFlag(Constants.DELETE_FLAG);
		meetingTypeService.update(data,new LambdaQueryWrapper<MeetingTypeDO>().in(MeetingTypeDO::getId,ids));
		return R.ok();
	}
	
}
